﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestCollection : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- Collections ---");
        }

        public void doTest()
        {
            testArrayList();
            testStack();
            testQueue();
            testHashTable();
        }

        private void testArrayList()
        {
            Console.WriteLine("--- ArrayList ---");
            ArrayList arrayList = new ArrayList();
            for (int i = 1; i < 11; i++)
            {
                arrayList.Add(i);
            }
            Console.Write("1 ~ 10  added, ");
            arrayList.RemoveAt(0);
            Console.Write("index 0 removed, ");
            arrayList.RemoveRange(4, 5);
            Console.Write("5 items removed from index 5, ");
            arrayList.Reverse();
            Console.WriteLine("Reversed ");

            Console.Write("ArrayList operation result : ");
            foreach (int val in arrayList)
            {
                Console.Write("{0} ", val);
            }
            Console.WriteLine();
        }

        private void testStack()
        {
            Console.WriteLine("--- Stack ---");
            Stack stack = new Stack();

            for (int i = 1; i < 11; i++)
            {
                stack.Push(i);
            }
            Console.WriteLine("1 ~ 10  pushed");

            Console.WriteLine("pop all value");
            while(stack.Count > 0)
            {
                Console.Write("{0} ", stack.Pop());
            }
            Console.WriteLine();
        }

        private void testQueue()
        {
            Console.WriteLine("--- Queue ---");
            Queue queue = new Queue();

            for (int i = 1; i < 11; i++)
            {
                queue.Enqueue(i);
            }
            Console.WriteLine("1 ~ 10  enqueued");

            Console.WriteLine("dequeue all value");
            while (queue.Count > 0)
            {
                Console.Write("{0} ", queue.Dequeue());
            }
            Console.WriteLine();
        }

        private void testHashTable()
        {
            Console.WriteLine("--- HashTable ---");
            Hashtable hashTable = new Hashtable();

            for (int i = 1; i < 11; i++)
            {
                hashTable.Add(i, i * 100);
            }
            Console.WriteLine("key = 1 ~ 10, value = key * 100 added");

            Console.WriteLine("dequeue all value");
            for(int key = 1; key < 11; key++)
            {
                Console.Write("{0} ", hashTable[key]);
            }
            Console.WriteLine();
        }
    }
}
